怎么判断数组所有元素都相同

标签:2023-06-25 16:20:34

通过ES6 Set方法去重,再判断去重后的数组长度是否等于1

let arr = [23, 23, 23, 23, 23, 23, 23];
let item = [...new Set(arr)];
if(item.length === 1){
  console.log("true")
}else{
  console.log("false")
}
原文出处:http://www.dongblog.com/notes/14.html
来源:博客网 转载请注明出处!

活跃用户

妄生
Ta还没有签名
彳亍
Ta还没有签名
(^随☆进^)
Ta还没有签名
间歇性思维跳跃
Ta还没有签名

友情链接


Warning: Smarty error: unable to read resource: "../../../templates/default/./common/foot/footer_index.htm" in /usr/home/hyu3925200001/htdocs/common/smarty/Smarty.class.php on line 1093

Warning: Smarty error: unable to read resource: "../../../templates/default/./common/foot/footer_index.htm" in /usr/home/hyu3925200001/htdocs/common/smarty/Smarty.class.php on line 1093